<?php
namespace backend\controllers;
use backend\models\Admin;
use yii\web\Controller;
use Yii;

class ManageController extends Controller{

    public function actionMailchangepass(){
        $this->layout = false;
        $time     = Yii::$app->request->get('timestamp');
        $username = Yii::$app->request->get('username');
        $token    = Yii::$app->request->get('token');
        $model = new Admin(['scenario' => 'changepass']);
        $myToken = $model->createToken($username, $time);
        if( $token != $myToken){
            $this->redirect(['public/login']);
            Yii::$app->end();
        }
        if(time() - $time > 300){
            $this->redirect(['public/login']);
            Yii::$app->end();
        }
        if(Yii::$app->request->isPost){
            $post = Yii::$app->request->post();
            if($re = $model->changePass($post)){
                Yii::$app->session->setFlash('info', '修改密码成功，请返回登录');
            }
        }
        $model->username = $username;
        return $this->render('mailchangepass', ['model' => $model]);
    }
}












